package com.yict.csms.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yict.common.entity.PageEntity;
import com.yict.common.service.impl.CommonService;
import com.yict.csms.system.dao.impl.OptionDaoImpl;
import com.yict.csms.system.entity.Option;
import com.yict.csms.system.entity.Wharf;
import com.yict.csms.system.service.IOptionService;

/**
 * 
 * 
 * @author Patrick.Deng
 * 
 */
@Service
public class OptionServiceImpl extends CommonService<Option, Long> implements
		IOptionService {
	@Autowired
	private OptionDaoImpl optionDaoImpl;

	public List<Option> search(String type, List<String> dataIds, Long wharfId) {
		StringBuilder queryString = new StringBuilder();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		String field = " order by c.wharf.wharfId asc";
		pageEntity = new PageEntity();
		queryString.append("from Option as c where 1=1");
		if (type != null && !"".equals(type)) {
			if (type.equals("rtgc_work")) {
				queryMap.put("ids", dataIds);
				queryString.append(" and c.operate.dictid in (:ids)");
			}
			if (type.equals("fl_work")) {
				queryMap.put("ids", dataIds);
				queryString.append(" and c.operate.dictid in (:ids)");
			}
		}
		if (wharfId != null && !"".equals(wharfId)) {
			queryMap.put("wharfId", wharfId);
			queryString.append(" and c.wharf.wharfId = :wharfId");
		}
		queryString.append(field);
		List<Option> list = optionDaoImpl.search(queryString.toString(),
				queryMap, null);
		return list;
	}

	public List<Option> search(HashMap<String, Object> map) {
		StringBuilder queryString = new StringBuilder();
		queryString.append("from Option as c where 1=1");
		if (map != null && map.size()>0) {
			if (map.get("dictType") != null && !"".equals(map.get("dictType"))) {
				queryString.append(" and c.operate.datatype = :dictType");
			}
		}
		List<Option> list = optionDaoImpl.search(queryString.toString(),
				map, null);
		return list;
	}

	public HashMap<Long, String> getWharf() {
		HashMap<Long, String> wharfMap = new HashMap<Long, String>();
		List<Wharf> wharfs = optionDaoImpl.getWharf();
		for (Wharf wharf : wharfs) {
			wharfMap.put(wharf.getWharfId(), wharf.getWharfName());
		}
		return wharfMap;
	}

}
